package org.jeecg.modules.lab.skill.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.jeecg.modules.lab.skill.entity.LabUserSkill;
import org.jeecg.modules.lab.skill.mapper.LabUserSkillMapper;
import org.jeecg.modules.lab.skill.service.ILabUserSkillService;
import org.jeecg.modules.lab.skill.vo.LabUserSkillPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;

/**
 * @Description: 实验人员专业能力表
 * @Author: jeecg-boot
 * @Date: 2024-04-17
 * @Version: V1.0
 */
@Service
public class LabUserSkillServiceImpl extends ServiceImpl<LabUserSkillMapper, LabUserSkill> implements ILabUserSkillService {

    @Autowired
    private LabUserSkillMapper labUserSkillMapper;

    @Override
    public void updateSkills(LabUserSkillPage labUserSkillPage) {
        String userId = labUserSkillPage.getId();
        List<LabUserSkill> labUserSkills = labUserSkillPage.getLabUserSkillList();
        QueryWrapper<LabUserSkill> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        labUserSkillMapper.delete(queryWrapper);
        if (labUserSkills != null && labUserSkills.size() > 0) {
            for (LabUserSkill userSkill : labUserSkills) {
                userSkill.setId(null);
                userSkill.setUserId(userId);
                labUserSkillMapper.insert(userSkill);
            }
        }
    }

    @Override
    public void copyUserSkill(String oldUserId, String newUserId) {
        QueryWrapper<LabUserSkill> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", oldUserId);
        List<LabUserSkill> labUserSkills = labUserSkillMapper.selectList(queryWrapper);
        if (labUserSkills != null && labUserSkills.size() > 0) {
            for (LabUserSkill userSkill : labUserSkills) {
                userSkill.setId(null);
                userSkill.setCreateTime(null);
                userSkill.setItemA(null);
                userSkill.setItemB(null);
                userSkill.setItemC(null);
                userSkill.setUserId(newUserId);
                labUserSkillMapper.insert(userSkill);
            }
        }
    }

    @Override
    public void newDataSkill() {
        List<LabUserSkill> labUserSkills = labUserSkillMapper.getXUserSkill();
        if (labUserSkills != null && labUserSkills.size() > 0) {
            for (LabUserSkill userSkill : labUserSkills) {
                labUserSkillMapper.insert(userSkill);
            }
        }
    }
}
